﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 10/04/2009
// Time: 22:33
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of ProductType.
	/// </summary>
	public class ProductType : common.DefaultClass, common.IClass
	{
		#region private declarations
			private string _name;
			private string _company_id;
			private string _create_date;
		#endregion
		
		#region properties
		public string name {
			get { return _name; }
			set { _name = value; }
		}
		
		public string companyId {
			get { return _company_id; }
			set { _company_id = value; }
		}
		
		public string createDate {
			get { return _create_date; }
			set { _create_date = value; }
		}
			
		#endregion
		
		public ProductType()
		{
			gsql.table = "common.product_type";
			_sequence  = "common.product_type_product_type_id_seq";        
		}
		
		public void clear()
		{
			_id = string.Empty;
			_name = string.Empty;
			_company_id = string.Empty;
			_create_date = string.Empty;
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id = dr["product_type_id"].ToString();
			_name = dr["product_type_name"].ToString();
			_company_id = dr["product_type_company_id"].ToString();
			_create_date = dr["product_type_create_date"].ToString();
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id, "product_type_id");
			gsql.setValue(_name, "product_type_name");
			gsql.setValue(_company_id, "product_type_company_id");
			gsql.setValue(_create_date, "product_type_create_date");
		}	
	}
    
	public class ProductTypes : common.DefaultList, common.IList
	{
		public ProductTypes()
		{
			gsql.table = "common.product_type";
		}
		
		/*public List<ProductType> items
		{
			get { return items; }
		}*/
		
		public ProductType get(Int32 index)
		{
			return (ProductType)items[index];
		}
		
		public ProductType get()
		{
			return (ProductType)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "product_type_company_id = "+Information.companyId;
			gsql.additionalWhere = "ORDER BY product_type_name";
			
			return mountList();
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				ProductType aux = new ProductType();
				aux.get(gsql.getRow(i));
				items.Add(aux);
			}
			return true;
		}
	}    	
}
